<?xml version="1.0" encoding="UTF-8" ?>



<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
	xmlns:asp="http://asp.net"
	xmlns:tmt="http://www.massimocorner.com/validator">
	<xsl:param name="DOTNET2"/>


	<xsl:variable name="EMPTY_GUID" select="'00000000-0000-0000-0000-000000000000'"/>
	
	<xsl:output method="xml" indent="yes"/>
	
	<xsl:template match="Instance">

/****************************************
 * Automatically generated by CodeGen
 ****************************************/
 
 
 /*
 
 
 <fieldset>
	<legend><xsl:value-of select="Name"/></legend>
 
	
	<xsl:for-each select="ClassAttribs/ClassAttributes">	
		<p><label><xsl:value-of select="Name"/></label>
		<xsl:if test="CType='single'">	
			<xsl:choose>
				<xsl:when test="SqlSPType='varchar(256)' or Type='int' or Type='double'">
&lt;asp:TextBox CssClass="string" runat="server" ID="txt<xsl:value-of select="PropertyName"/>" /&gt;
				</xsl:when>
				<xsl:when test="SqlSPType='ntext'">
&lt;asp:TextBox CssClass="string" TextMode="MultiLine" runat="server" ID="txt<xsl:value-of select="PropertyName"/>" /&gt;
				</xsl:when>
				<xsl:when test="Type='bool'">
&lt;asp:CheckBox ID="chk<xsl:value-of select="PropertyName"/>" runat="server" class="bool" /&gt;
				</xsl:when>
			</xsl:choose>
		</xsl:if>
		
		<xsl:if test="KnownClass='true'">
&lt;asp:DropDownList ID="ddl<xsl:value-of select="PropertyName"/>" CssClass="KnownClass" runat="server" /&gt;
		</xsl:if>
		</p>
	</xsl:for-each>
 </fieldset>

 */


using System;

namespace <xsl:value-of select="HeaderInfo/ProjectName"/>.web
{
	public partial class <xsl:value-of select="Name"/> : System.Web.UI.Page
	{
	
		protected void Init ( )
		{
		    InitControls ( );
		    if ( ! IsPostBack ) InitDataSources ( );
		}
			
			
			
			
		protected <xsl:value-of select="HeaderInfo/ProjectName"/>Library.Instance.<xsl:value-of select="Name"/> BuildObject ( )
		{
			<xsl:value-of select="HeaderInfo/ProjectName"/>Library.Instance.<xsl:value-of select="Name"/> obj =
				new <xsl:value-of select="HeaderInfo/ProjectName"/>Library.Instance.<xsl:value-of select="Name"/> ();
			<xsl:for-each select="ClassAttribs/ClassAttributes">	
				<xsl:if test="CType='single'">
					<xsl:choose>
						<xsl:when test="SqlSPType='varchar(256)' or SqlSPType='ntext'">
			obj.<xsl:value-of select="PropertyName"/> = txt<xsl:value-of select="PropertyName"/>.Text;</xsl:when>
			
						<xsl:when test="Type='int'">
			// Note: This may need error checking server side if client does not pick it up
			obj.<xsl:value-of select="PropertyName"/> = int.Parse ( txt<xsl:value-of select="PropertyName"/>.Text );</xsl:when>
						
						<xsl:when test="Type='double'">
			// Note: This may need error checking server side if client does not pick it up
			obj.<xsl:value-of select="PropertyName"/> = double.Parse ( txt<xsl:value-of select="PropertyName"/>.Text );</xsl:when> 
			
						<xsl:when test="Type='bool'">
			obj.<xsl:value-of select="PropertyName"/> = chk<xsl:value-of select="PropertyName"/>.Checked;</xsl:when>
					
					</xsl:choose>
				</xsl:if>
				
				<xsl:if test="KnownClass='true'">
			obj.<xsl:value-of select="PropertyName"/> = new <xsl:value-of select="//HeaderInfo/ProjectName"/>.DataObject.<xsl:value-of select="PropertyName"/> ( new Guid ( ddl<xsl:value-of select="PropertyName"/>.SelectedValue ) );
				</xsl:if>
			</xsl:for-each>

			return obj;
		}
		
		public void InitDataSources ( )
		{
			<xsl:value-of select="HeaderInfo/ProjectName"/>Library.Instance.<xsl:value-of select="Name"/> obj =
				new <xsl:value-of select="HeaderInfo/ProjectName"/>Library.Instance.<xsl:value-of select="Name"/> ();
		<xsl:for-each select="ClassAttribs/ClassAttributes">
			<xsl:if test="KnownClass='true'">
			ddl<xsl:value-of select="PropertyName"/>.DataSource = obj.<xsl:value-of select="PropertyName"/>_VALS;
			ddl<xsl:value-of select="PropertyName"/>.DataValueField = "ObjectID";
			ddl<xsl:value-of select="PropertyName"/>.DataTextField = "Name";
			ddl<xsl:value-of select="PropertyName"/>.DataBind ( );
			
			ddl<xsl:value-of select="PropertyName"/>.Items.Insert ( 0 , new System.Web.UI.WebControls.ListItem ( "Please Select" , Guid.Empty.ToString ( ) ) );
			</xsl:if>
			
			<xsl:if test="CType='single'">
				<xsl:choose>
					<xsl:when test="Type='int' or Type='double'">
			txt<xsl:value-of select="PropertyName"/>.Text = "0";
					</xsl:when>
				</xsl:choose>
			</xsl:if>
		</xsl:for-each>
		}
			
			
		protected void InitControls ( )
		{
				
		<xsl:for-each select="ClassAttribs/ClassAttributes">	
			<xsl:if test="CType='single'">
				<xsl:choose>
					<xsl:when test="SqlSPType='varchar(256)'">
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:errorclass" , "errorclass" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:required" , "true" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:message" , "<xsl:value-of select="PropertyName"/> is required" );	
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:maxlength" , "255" );	
					</xsl:when>

					<xsl:when test="SqlSPType='ntext'">
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:errorclass" , "errorclass" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:required" , "true" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:message" , "<xsl:value-of select="PropertyName"/> is required" );	
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:maxlength" , "4000" );	
					</xsl:when>
					<xsl:when test="Type='int'">
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:errorclass" , "errorclass" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:required" , "true" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:message" , "<xsl:value-of select="PreoprtyName"/> is required" );	
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:pattern" , "integer" );	
					</xsl:when>
					<xsl:when test="Type='double'">
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:errorclass" , "errorclass" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:required" , "true" );
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:message" , "<xsl:value-of select="PropertyName"/> is required" );	
			txt<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:pattern" , "number" );	
					</xsl:when>
					
					
				</xsl:choose>
			</xsl:if>
			
			<xsl:if test="KnownClass='true'">
			ddl<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:errorclass" , "errorclass" );
			ddl<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:invalidvalue", "<xsl:value-of select="$EMPTY_GUID"/>" );
			ddl<xsl:value-of select="PropertyName"/>.Attributes.Add ( "tmt:message" , "<xsl:value-of select="PropertyName"/> is required" );	
			</xsl:if>

		</xsl:for-each>

		}
		
	}

}
	</xsl:template>
	
	
</xsl:stylesheet>